home *** CD-ROM | disk | FTP | other *** search
/ Nebula 2 / Nebula Two.iso / NextAnswers / 1179_fat_libraries.rtf < prev    next >
Text File  |  1995-06-12  |  6KB  |  171 lines

  1. {\rtf0\ansi{\fonttbl\f0\fnil Times-Roman;\f1\fmodern Courier;\f2\fmodern Ohlfs;}
  2. \paperw9840
  3. \paperh8400
  4. \margl120
  5. \margr120
  6. {\colortbl;\red0\green0\blue0;}
  7. \pard\tx520\tx1060\tx1600\tx2120\tx2660\tx3200\tx3720\tx4260\tx4800\tx5320\f0\b0\i0\ulnone\fs28\fc0\cf0 Q:  I have libraries compiled for NeXT 3.0 machines that I need to use on NEXTSTEP for Intel Processors.  What should I do to make them work?\
  8. \
  9. Q:  I wrote an application under 3.1 on an Intel NEXTSTEP platform that uses a library I wrote under 3.0, but it won't link properly—why?\
  10. \
  11. Q:  How do I make my 3.0 libraries accessible in a multi-architecture form to 3.1 applications?\
  12. \
  13. A:  Libraries that were compiled under NEXTSTEP 3.0 and earlier should work fine under 3.1—for NeXT hardware.  Some extra work is required to make them work properly under NEXTSTEP 3.1 for Intel Processors.  Because the m68k architecture and the i386 architectures are radically different, it is necessary for NEXTSTEP to have access to a binary for both architectures in order to provide an executable that runs on both machines.  Libraries, being binary files containing machine instructions, are no different from any application in this respect.  Building multi-architecture applications is easy, since the 
  14. \b Project Builder
  15. \b0  application takes care of the details of building Multi-Architecture Binary files (MAB files) when requested.  But 
  16. \b Project Builder
  17. \b0  doesn't manage libraries, so an application that you have compiled may fail to link properly because of the lack of a library matching the architecture type of the machine you are compiling for.\
  18. \
  19. 3.1 provides a new utility, 
  20. \b libtool
  21. \b0 , for generating multi-architecture (or "fat") libraries.  
  22. \b libtool
  23. \b0  is intended to replace both the 
  24. \b ar
  25. \b0  and 
  26. \b ranlib
  27. \b0  utilities.  Traditionally, the construction of a library is managed by a 
  28. \b Makefile
  29. \b0 , which usually does roughly the following:\
  30. \
  31.  
  32. \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\fi-980\li980\fc0\cf0 1)    Compiles the .c and .m (source) files into .o (object) files, using the compiler (
  33. \b cc
  34. \b0 ).\
  35. 2)    Archives the resulting .o files into a .a (library) file, using the archiver (
  36. \b ar
  37. \b0 ).\
  38. 3)    Generates a table of contents file in the archive, using the 
  39. \b ranlib
  40. \b0  utility.\
  41.  
  42. \pard\tx520\tx1060\tx1600\tx2120\tx2660\tx3200\tx3720\tx4260\tx4800\tx5320\fc0\cf0 \
  43. A simple sequence to generate a linkable library starting from just two C files might be:\
  44. \
  45.  
  46. \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\f1\fs24\fc0\cf0     /bin/cc -c -o first.o first.c\
  47.     /bin/cc -c -o second.o second.c\
  48.     /bin/ar ruv libsilly.a first.o second.o\
  49.     /bin/ranlib libsilly.a\
  50.  
  51. \pard\tx520\tx1060\tx1600\tx2120\tx2660\tx3200\tx3720\tx4260\tx4800\tx5320\fc0\cf0 \
  52.  
  53. \f0\fs28 Under 3.1, however, steps 2 and 3 above are combined into one 
  54. \b libtool
  55. \b0  call, so that the equivalent sequence would be:\
  56.  
  57. \f1\fs24 \
  58.  
  59. \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\fc0\cf0     /bin/cc -c -o first.o first.c\
  60.     /bin/cc -c -o second.o second.c\
  61.     /bin/libtool -o libsilly.a first.o second.o\
  62.  
  63. \pard\tx520\tx1060\tx1600\tx2120\tx2660\tx3200\tx3720\tx4260\tx4800\tx5320\fc0\cf0 \
  64.  
  65. \f0\fs28 Notice that the call to 
  66. \b ar
  67. \b0 , with the r, u, and v switches on, has been replaced with a call to 
  68. \b libtool
  69. \b0 , and that calling 
  70. \b ranlib
  71. \b0  is no longer necessary.  The r, u, and v switches allowed 
  72. \b ar
  73. \b0  to update only the objects that were newer than the ones in the archive; the 
  74. \b libtool
  75. \b0  call doesn't have this capability, but is much faster than 
  76. \b ar
  77. \b0 , and in addition, it is capable of archiving fat objects, which 
  78. \b ar
  79. \b0  cannot do.\
  80. \
  81. So where do multiple-architecture objects come in?  So-called "fat" objects are generated when the compiler is told to generate objects of more than one architecture type, using the 
  82. \b -arch 
  83. \b0 flag.  If you look at the compile text field in Project Builder, you should notice that it uses this flag whenever it is asked to generate something for both the m68k and i386 architectures.  The change needed to the above sequence is:\
  84. \
  85.  
  86. \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\f1\fs24\fc0\cf0     /bin/cc -arch m68k -arch i386 -c -o first.o first.c\
  87.     /bin/cc -arch m68k -arch i386 -c -o second.o second.c\
  88.     /bin/libtool -o libsilly.a first.o second.o\
  89.  
  90. \pard\tx520\tx1060\tx1600\tx2120\tx2660\tx3200\tx3720\tx4260\tx4800\tx5320\fc0\cf0 \
  91.  
  92. \f0\fs28 And that's all there is to it.  The gains to library-building using 
  93. \b libtool
  94. \b0  are the ability to make fat libraries, and the elimination of the need to use 
  95. \b ranlib
  96. \b0 .  The loss is the ability to update only those files in the archive that have timestamps older than the input files—in general, the amount of time lost in moving from 
  97. \b ar
  98. \b0  and 
  99. \b ranlib
  100. \b0  to 
  101. \b libtool
  102. \b0  should be minimal, if any.\
  103. \
  104. For the Makefile minded, here's a simple example of what needs to be changed.  The first file is the original, which compiles into a single-architecture library, and the second file will generate the multi-architecture library:\
  105. \
  106.  
  107. \f1\fs24\fc1\cf1     -------------------------------\
  108. CC        = /bin/cc\
  109. RANLIB    = /bin/ranlib\
  110. AR        = /bin/ar\
  111. ARFLAGS    = ruv\
  112. \
  113. CFLAGS    = -g -O2 -arch m68k -arch i386\
  114. \
  115. SRCS        = first.c second.c\
  116. \
  117. OBJS = $(SRCS:.c=.o)\
  118. \
  119. .c.o: ; $(CC) $(CFLAGS) -c -o $@ $<\
  120. \
  121. all: libsilly.a\
  122. \
  123. libsilly.a: $(OBJS)\
  124.     $(AR) $(ARFLAGS) $@ $(OBJS)\
  125.     $(RANLIB) $@\
  126. \
  127. clean: ; /bin/rm -f *.o *.a *~\
  128. -----------------------------------\
  129. CC        = /bin/cc\
  130. LIBTOOL    = /bin/libtool\
  131. \
  132. CFLAGS    = -g -O2 -arch m68k -arch i386\
  133. \
  134. SRCS        = first.c second.c\
  135. \
  136. OBJS = $(SRCS:.c=.o)\
  137. \
  138. .c.o: ; $(CC) $(CFLAGS) -c -o $@ $<\
  139. \
  140. all: libsilly.a\
  141. \
  142. libsilly.a: $(OBJS)\
  143.     $(LIBTOOL) -o $@ $(OBJS)\
  144. \
  145. clean: ; /bin/rm -f *.o *.a *~\
  146. \
  147. --------------------------\
  148.  
  149. \f0\fs28\fc0\cf0 \
  150. See Also:\
  151. \
  152. Man Pages:  
  153. \b lipo
  154. \b0 (1), 
  155. \b libtool
  156. \b0 (1), 
  157. \b ar
  158. \b0 (1), 
  159. \b ranlib
  160. \b0 (1).\
  161. Release Notes:  Compiler.rtf, FatFiles.rtf, ProjectBuilder.rtf\
  162. \
  163. QA883\
  164. \
  165.  
  166. \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\fc1\cf1 Valid for 3.1\
  167.  
  168. \pard\tx520\tx1060\tx1600\tx2120\tx2660\tx3200\tx3720\tx4260\tx4800\tx5320\fc0\cf0 \
  169.  
  170.  
  171.